package cn.wiseda.finance.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.wiseda.finance.entity.Store;
import cn.wiseda.finance.services.StoreService;

@Controller
@RequestMapping("store")
public class StoreController {

    @Resource
    private StoreService storeService;

    @RequestMapping("index.jhtml")
    public String index() {
        return "lease/store_entering";
    }

    @RequestMapping("save.jhtml")
    public String saveStore(Store store) {
        System.out.println(store);
//        String remarks = store.getRemarks();
//        store.setRemarks(HtmlEncoder.block(remarks));
        storeService.saveStore(store);
        return "redirect:list.jhtml";
    }

    @RequestMapping("list.jhtml")
    public String list(Model model) {
        List<Store> list = storeService.queryStores();
        model.addAttribute("stores", list);
        return "lease/list";
    }

    @RequestMapping("store.jhtml")
    public String getStore(int id, Model model) {
        Store store = storeService.queryStore(id);
        model.addAttribute("store", store);
        return "lease/store_modify";
    }
    
    @RequestMapping("modify.jhtml")
    public String modify(Store store){
//        String remarks = store.getRemarks();
//        store.setRemarks(HtmlEncoder.block(remarks));
        storeService.modifyStore(store);
        return "redirect:list.jhtml";
    }
    
    @RequestMapping("export.jhtml")
    public void export(HttpServletResponse response){
        List<Store> store = storeService.queryStores();
        String[] title = new String[]{"ID","房屋编号","物业地址","房屋类型","建筑面积","使用面积","装修情况","出租价位","目前状态","备注"};
        ExportExcel.exportExcel("store.xls", title, store, response);
    }

}
